package StructuralPattern.Proxy.RMI;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class Server extends HelloImpl{
    public Server() {}

    public static void main(String[] args) {
        try {
            // Instantiating the implementation class
            HelloImpl hello = new HelloImpl();

            // Exporting the object of implementation class
            // Here we are exporting the remote object to the stub
            Hello stub = (Hello) UnicastRemoteObject.exportObject(hello,0);

            // Binding the remote object (stub) in the registry
            Registry registry = LocateRegistry.createRegistry(1888);

            registry.bind("Hello", stub);
            System.err.println("Server ready");

        } catch (RemoteException | AlreadyBoundException e) {
            System.err.println("System exception: " + e.toString());
            e.printStackTrace();
        }
    }
}
